﻿using ApplicationModels.A04.Interactions;
using Commons.Requests;
using Commons.Responses;
using EntityModels.E04.Interactions;
using IApplicationServices;
using Microsoft.AspNetCore.Mvc;

namespace WebAPI.Controllers
{
    [Route("[controller]/[action]")]
    public class CommentController : BaseController<int, Comment, CommentAM>
    {
        private readonly ICommentService _commentService;
        public CommentController(ICommentService service):base(service) 
        {
            _commentService = service;
        }

        public override async Task<DatasResponse<CommentAM>> GetBySelectAsync([FromQuery] PagingRequest req)
        {
            return await  _commentService.GetCommentsByPhotographIdAsync(req.PageIndex, req.PageSize, req.SearchValue);
        }
        public override async Task<MessageResponse> AddAsync(CommentAM apiEntity)
        {
            apiEntity.AppUserId = AppUserId;
            return await base.AddAsync(apiEntity);
        }
        /// <summary>
        /// 点赞
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageResponse> IncreaseLikeAsync(int id)
        {
            return await _commentService.IncreaseLikeAsync(id);
        }
        /// <summary>
        /// 取消点赞
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        [HttpGet]
        public async Task<MessageResponse> ReduceLikeAsync(int id)
        {
            return await _commentService.ReduceLikeAsync(id);
        }
    }
}
